fun tolnt (b: int) : (int list -> int) =
    let
        (* 辅助函数，将列表转换为整数 *)
        fun toInt [] = 0
          | toInt (x::xs) = x + b * toInt xs
    in
        toInt
    end;


val base2Tolnt = tolnt 2;    

(* 测试例子 *)
val result1 = base2Tolnt [0, 1];    (* [0, 1] -> 1 *)
val result2 = base2Tolnt [1, 0, 1];  (* [1, 0, 1] -> 5 *)
val result3 = base2Tolnt [1, 1, 1];  (* [1, 1, 1] -> 7 *)

(* 输出结果 *)
val _ = print ("Result for [0, 1]: " ^ Int.toString result1 ^ "\n");
val _ = print ("Result for [1, 0, 1]: " ^ Int.toString result2 ^ "\n");
val _ = print ("Result for [1, 1, 1]: " ^ Int.toString result3 ^ "\n");